<html>

 <head><title>Page with iframe and link</title>
 <script>
  function simulateClick(target) {
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,
                       0, 0, 0, 0, 0, false, false,
                       false, false, 0, null);

    return target.dispatchEvent(evt);
  }

  function setPortNumber(portNumber) {
    var link = document.getElementById("cross_site_link");
    link.setAttribute("href", "http://foo.com:" + portNumber + "/title2.html");
    return true;
  }

  function clickCrossSiteLink() {
    return simulateClick(document.getElementById("cross_site_link"));
  }
 </script>
 </head>

<a href="http://foo.com/title2.html" id="cross_site_link">cross-site</a><br>

<p>This page has an iframe. Yay for iframes!
<p><iframe src="about:blank"></iframe>

</html>
